<template>
    <div class="process-monitoring-box">
        <commpVxeTable
         :key="dataTableKey"
         :config="dataTableConfig" 
         :columns="columnsVxe" 
         :formItem="formItem"
         ref="acceptanceRegistrationRef"
         @checkboxChange="selectedRowKeysChange"
         @searchEvent="searchEvent"
         >
            <template v-slot:externalOperations="{data}">
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="exportClick()">导出</a-button>
                    </template>
                </vxe-form-item>
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="setStatusClick()">批量设置状态</a-button>
                    </template>
                </vxe-form-item>
                <vxe-form-item>
                    <template>
                        <a-button class="blue-btn" type="primary" @click="setPositionClick()">批量设置所属库</a-button>
                    </template>
                </vxe-form-item>
            </template>
            <template v-slot:username_name="{row}">
                <a @click="infoEdit(row)">{{ row.username }}</a>
            </template>
            <!-- <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                <a-form layout="inline" class="search-form" >
                    <a-form-item >
                        <a-button class="red-btn" type="primary" @click="deleteClick(row)">删除</a-button>
                    </a-form-item>
                </a-form>
            </template> -->
        </commpVxeTable>
        <a-modal
            :title="batchData.type == 1?'修改账户信息':(batchData.type == 'fssk'?'批量修改所属库':'批量修改状态')"
            :visible="visible"
            @ok="handleOk"
            @cancel="visible = false"
        >
            <a-form layout="inline" class="info-manage-status-form">
                <a-form-item label="所属库" v-if="batchData.type == 'fssk'|| batchData.type == 1">
                    <compSelector
                        v-model="batchData.fssk"
                        :defaultValue="batchData.fssk"
                        compType="Select"
                        dictionaryType="核查员所属库"
                    />
                </a-form-item>
                <a-form-item label="有效状态" v-if="batchData.type == 'fstate' || batchData.type == 1">
                    <compSelector
                        v-model="batchData.fstate"
                        :defaultValue="batchData.fstate"
                        compType="Select"
                        dictionaryType="核查员有效状态"
                    />
                </a-form-item>
            </a-form>
        </a-modal>
    </div>
</template>
<script>
import assessCheckApi from './service/api'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import blobType from '@/common/blobType'
import moment from 'moment'
import compSelector from '@/components/compSelector/compSelector.vue'
import {
    queryJobByJobIdServe,
    getSqsxBm,
    spcyJcydjbfqJcydjb,
    spcyJcydjbreplateFile,
    jcyglexportJcyLbData,
    jcyglbatchSzSsk,
    jcyglbatchSzJcyState,
    jcyglupdateUserInfo,
} from './service/index'
export default {
    components:{
        commpVxeTable,
        compSelector,
    },
    props:{

    },
    data(){
        return{
            visible:false,
            batchData:{},
            addEditParameter:{},
            dataTableKey:null,
            formItem:[
                {
                    label: '审评类型',//(检查员登记类别)字典
                    model: 'flx',
                    type:'Radio',
                    dictionaryType:'检查员登记类别',
                    defaultValue:'药物临床',
                },{
                    label: '有效状态',
                    model: 'fstate',
                    type:'Select',
                    dictionaryType:'核查员有效状态'
                },{
                    label: '姓名',
                    model: 'realname',
                },{
                    label: '工作单位',
                    model: 'fgzdw',
                },{
                    label: '所属库',
                    model: 'fssk',
                }],//
            columnsVxe:[
            { 
                type: 'checkbox', 
                width: 60 ,
                fixed: 'left'
            },{
                title: '账号', //列头显示文字
                field: 'username',
                slots: { default: 'username_name' },
                width:120,
            },{
                title: '真实姓名', //列头显示文字
                field: 'realname',
                width:90,
            },{
                title: '手机号码',
                field: 'phone',
                width:115,
            }
            ,{
                title: '工作单位',
                field: 'fgzdw',
            }
            ,{
                title: '工作状态',
                field: 'fgzzt',
                width:80,
            },{
                title: '有效状态',
                field: 'fstate',
                width:80,
            }
            ,{
                title: '所属区域',
                field: 'fssqy',
                width:80,
            }
            ,{
                title: '所属库',
                field: 'fssk',
                width:70,
            },{
                title: '专业特长',
                field: 'fszly',
            },{
                title: '审评类型',
                field: 'flx',
                width:150,
            }
            // ,{
            //     title: '操作',
            //     field: 'id',
            //     slots: { default: 'operation_btn' },
            //     fixed: 'right',
            //     width:260,
            // }
            ],
            dataTableConfig:{
                api: assessCheckApi.list,
                rowId: 'id',
                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                paramet:{
                    flx:'药物临床'
                }
            },
            selectedRowKeysArr:[],
            searchFrom:{},
        }
    },
    watch:{

    },
    mounted(){
        
    },
    methods:{
        cjhfClick(){
            this.$route.push('/enterpriseWithdrawalApplication/index')
        },
        timeProcessing(val){
            if(val){
                val = val.slice(0,11)
            }
            return val
        },
        shareQRCodeClick(){//分享二维码
            this.$refs.QRQueryResultsRef.visibleQRQrCode = true
            this.$refs.QRQueryResultsRef.getData()
        },
        batchDeleteClick(){//批量删除

        },
        searchEvent(searchFrom){//搜索
            this.searchFrom = {...this.dataTableConfig.paramet,...searchFrom}
        },
        selectedRowKeysChange(row){//获取选中表格rowKey
            this.selectedRowKeysArr = []
            row.forEach(item => {
                this.selectedRowKeysArr.push(item.id)
            });
        },
        exportClick(val){//下载
            var that = this
            spcyJcydjbreplateFile({id:val.id}).then((data) => {
                if (!data) {
                    that.$message.warning('文件下载失败')
                    return
                }
                    let index = blobType.suffix.indexOf('.pdf')
                    let url = window.URL.createObjectURL(new Blob([data], { type:blobType.type[index] }))
                    let link = document.createElement('a')
                    link.style.display = 'none'
                    link.href = url
                    link.setAttribute('download', '审评员登记表' + '.pdf')
                    document.body.appendChild(link)
                    link.click()
                    document.body.removeChild(link) //下载完成移除元素
                    window.URL.revokeObjectURL(url) //释放掉blob对象
                // }
            })
        },
        viewClick(row){//查看
            this.$refs.refModel.visible = true
            this.$refs.refModel.getData(row.id)
        },
        deleteClick(val){//删除
            var that = this
            this.$confirm({
                title:'确认要删除吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    spcyJcydjbfqJcydjb({id:val.id}).then(res=>{
                        if(res.code == 200){
                            that.$refs.acceptanceRegistrationRef.searchEvent()
                            that.$message.success(res.message)
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                }
            })
        },
        exportClick(){
            var that = this
            var fileName = '审评类型'
            let param = { }
            if(that.selectedRowKeysArr.length){
                param = {
                    ids:that.selectedRowKeysArr.join(','),
                }
            }else{
                param = {...that.searchFrom}
            }
            jcyglexportJcyLbData(param).then((data) => {
                if (!data) {
                    that.$message.warning('文件下载失败')
                    return
                }
                if (typeof window.navigator.msSaveBlob !== 'undefined') {
                    window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), fileName + '.xls')
                } else {
                    let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
                    let link = document.createElement('a')
                    link.style.display = 'none'
                    link.href = url
                    link.setAttribute('download', fileName + '.xls')
                    document.body.appendChild(link)
                    link.click()
                    document.body.removeChild(link) //下载完成移除元素
                    window.URL.revokeObjectURL(url) //释放掉blob对象
                }
            })
        },
        setPositionClick(){
            this.batchData = {}
            if(this.selectedRowKeysArr.length){
                this.batchData.type = 'fssk'
                this.batchData.fssk = ''
                this.visible = true

            }else{
                this.$message.warning('请先选择设置项')
            }
        },
        setStatusClick(){
            this.batchData = {}
            if(this.selectedRowKeysArr.length){
                this.batchData.type = 'fstate'
                this.batchData.fstate = ''
                this.visible = true

            }else{
                this.$message.warning('请先选择设置项')
            }
        },
        infoEdit(row){
            this.batchData = {...row,type:1}
            this.visible = true
        },
        handleOk(){
            if(this.batchData.type == 'fssk'){
                if(this.batchData.fssk){
                    jcyglbatchSzSsk({fssk:this.batchData.fssk,ids:this.selectedRowKeysArr.join(',')}).then(res=>{
                        if(res.code == 200){
                            this.dataTableKey = Date.now()
                            this.$message.success(res.message)
                            this.visible = false
                        }else{
                            this.$message.warning(res.message)
                        }
                    })
                }else{
                    this.$message.warning('请先选择所属库')
                }
                
            }
            if(this.batchData.type == 'fstate'){
                if(this.batchData.fstate){
                    jcyglbatchSzJcyState({fstate:this.batchData.fstate,ids:this.selectedRowKeysArr.join(',')}).then(res=>{
                        if(res.code == 200){
                            this.$refs.acceptanceRegistrationRef.searchEvent()
                            this.$message.success(res.message)
                            this.visible = false
                        }else{
                            this.$message.warning(res.message)
                        }
                    })
                }else{
                    this.$message.warning('请先选择有效状态')
                }
                
            }
            if(this.batchData.type == 1){
                jcyglupdateUserInfo({fstate:this.batchData.fstate,fssk:this.batchData.fssk,id:this.batchData.id}).then(res=>{
                    if(res.code == 200){
                        this.$refs.acceptanceRegistrationRef.searchEvent()
                        this.$message.success(res.message)
                        this.visible = false
                    }else{
                        this.$message.warning(res.message)
                    }
                })
            }
        }
    }
}
</script>
<style lang="less">
    .info-manage-status-form{
        .ant-form-item-label{
            width: 70px;
        }
    }
</style>